import java.lang.reflect.InvocationTargetException;

public class Factory {
    public static Fruit getInstance(String fruitName) {
        Fruit fruit = null;
        Class<?> fc = null;
        try {
            fc = Class.forName(fruitName);
            fruit = (Fruit)fc.getDeclaredConstructor().newInstance();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
        return fruit;
    }
}
